#include <bits/stdc++.h>
using namespace std;

int T;
int n, m, L, V, d[100007], v[100007], a[100007], p[100007];

int main(){
	freopen("detect.in", "r", stdin);
	freopen("detect.out", "w", stdout);
	scanf("%d", &T);
	while(T--){
		int P = 0;
		scanf("%d%d%d%d", &n, &m, &L, &V);
		for(int i = 1; i <= n; i++)
			scanf("%d%d%d", &d[i], &v[i], &a[i]);
		for(int i = 1; i <= m; i++)
			scanf("%d", &p[i]);
		for(int i = 1; i <= n; i++){
			if(v[i] <= V && a[i] <= 0) continue;
			if(v[i] > V && a[i] == 0 && p[m] >= d[i]) ++P;
		}
		printf("%d %d\n", P, m - (P == 0 ? 0 : 1));
	}
	return 0;
}
